

local excel = load_excel('挑战设定.xlsx','挑战')
for name,data in pairs(excel) do
    local cool = data.cool
    data.tip = data['效果']
    if name~='杀敌挑战' then
        data.cooldown_mode = 1
        data.charge_max_stack = 3
        data.charge_cool = cool
        data.cool = 0
    end
    ac.lni('skill',name,data)
end

local list = {
    '金币挑战',
    '经验挑战',
    '杀敌挑战',
}
for _,name in ipairs(list) do
    local mt = ac.skill[name]
    mt.physics = true
    mt.count = 0
    mt.show_cool = 1

    function mt:on_add()
        self:set_stack(0)
        if self.charge_cool>0 then
            self:set_charge_cd(self.charge_cool or 1)
        else
            self:set_cd(self.cool or 1)
        end
    end

    function mt:on_cast_shot()
        local unit = self.owner
        local player = unit.owner
        local name = self.unit_name
        self.count = self.count + 1
        ac.timer(200,self.data1,function()
            local unit = player:add_enemy(name,true)
            unit:set_enemy_level(ac.enemy.day)
            if name=='金币怪' then
                unit['金币'] = math.random(self.data2,self.data3) * (1 + (self.count - 1)*0.2)
            elseif name=='经验怪' then
            elseif name=='杀敌怪' then
                unit['杀敌'] = math.random(self.data2,self.data3)
            end
        end)
    end

end


ac.game:event '玩家-选择英雄完毕'(function(_,player,hero)
    local book = {}
    for a,name in ipairs(list) do
        local skill = hero:add_skill(name)
        book[a] = skill
    end
    player:set_data('挑战技能表',book)
    player:notify('玩家-设置挑战内容',player,book)
end)


ac.sync:event '玩家-点击挑战'(function(_,player,index)
    local list = player:get_data('挑战技能表')
    local temp = list and list[index]
    if temp then
        temp:cast()
    end
end)

ac.game:event '游戏-隐藏商店'(function()
    ac.each_player(function(player)
        player:set_data('挑战技能表',nil)
        player:notify('玩家-设置挑战内容',player)
    end)
end)





